package com.tancire.question.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.question.domain.TrainProblem;
import com.tancire.question.service.ITrainProblemService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 答题题目Controller
 *
 * @author tancire
 * @date 2024-10-09
 */
@RestController
@RequestMapping("/question/trainProblem")
public class TrainProblemController extends BaseController {
    @Resource
    private ITrainProblemService trainProblemService;

    /**
     * 查询答题题目列表
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblem:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainProblem trainProblem) {
        startPage();
        List<TrainProblem> list = trainProblemService.selectTrainProblemList(trainProblem);
        return getDataTable(list);
    }

    /**
     * 导出答题题目列表
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblem:export')")
    @Log(title = "答题题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainProblem trainProblem) {
        List<TrainProblem> list = trainProblemService.selectTrainProblemList(trainProblem);
        ExcelUtil<TrainProblem> util = new ExcelUtil<TrainProblem>(TrainProblem.class);
        util.exportExcel(response, list, "答题题目数据");
    }

    /**
     * 获取答题题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(trainProblemService.selectTrainProblemById(id));
    }

    /**
     * 新增答题题目
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblem:add')")
    @Log(title = "答题题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainProblem trainProblem) {
        return toAjax(trainProblemService.insertTrainProblem(trainProblem));
    }

    /**
     * 修改答题题目
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblem:edit')")
    @Log(title = "答题题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainProblem trainProblem) {
        return toAjax(trainProblemService.updateTrainProblem(trainProblem));
    }

    /**
     * 删除答题题目
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblem:remove')")
    @Log(title = "答题题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(trainProblemService.deleteTrainProblemByIds(ids));
    }

    /**
     * 查询答题题目列表
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblem:list')")
    @GetMapping("/list/extr/activity")
    public TableDataInfo listExtrActivity(TrainProblem trainProblem) {
        startPage();
        List<TrainProblem> list = trainProblemService.selectTrainProblemListExtr(trainProblem);
        return getDataTable(list);
    }
}
